from django.contrib.auth.models import User
from django.db import models

from apps.users.models import Users


# Create your models here.
class MenuType(models.Model):
    name = models.CharField("name", max_length=256)
    create_date = models.DateTimeField('date created', auto_now_add=True)
    operator = models.ForeignKey(Users, on_delete=models.SET_NULL, null=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'menu_type'


class Menu(models.Model):
    name = models.CharField("name", max_length=256, null=True, blank=True)
    image = models.CharField('image', max_length=256, null=True, blank=True)
    price = models.CharField("price", max_length=256, null=True, blank=True)
    desc = models.TextField("desc", null=True, blank=True)
    create_time = models.DateTimeField('created', auto_now_add=True)
    type = models.ForeignKey(MenuType, on_delete=models.CASCADE)
    operator = models.ForeignKey(Users, on_delete=models.SET_NULL, null=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'menu'


class MenuItem(models.Model):
    menu = models.ManyToManyField(Menu, related_name='items', blank=True, null=True)
    user = models.ForeignKey(Users, on_delete=models.SET_NULL, null=True, related_name='menu_items_as_user')
    chef = models.ForeignKey(Users, on_delete=models.SET_NULL, null=True, related_name='menu_items_as_chef')
    create_date = models.DateTimeField('date created', auto_now_add=True)

    class Meta:
        db_table = 'menu_item'
